package be.bonamis.timesheet.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import be.bonamis.timesheet.service.CreateDb;
import be.bonamis.timesheet.service.PersonService;
import be.bonamis.timesheet.service.ProjectService;

@Controller
@RequestMapping("/folders")
public class FolderController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(PersonController.class);
	
	private static final String MODEL_ATTRIBUTE_PERSON = "person";
	private static final String MODEL_ATTRIBUTE_PROJECTS = "projects";
	private static final String FOLDERS_VIEW = "folders/choose";
	
	@Resource
    private ProjectService projectService;
	
	@Resource
    private PersonService personService;
	
	@Autowired
	private CreateDb createDb;	

	@RequestMapping(value = "/{id}", method=RequestMethod.GET)
    public String showList(@PathVariable Long id, Model model)  {
        LOGGER.debug("Rendering project list page");       
                
        model.addAttribute(MODEL_ATTRIBUTE_PERSON, personService.findById(id));
        model.addAttribute(MODEL_ATTRIBUTE_PROJECTS, projectService.findAll());

        return FOLDERS_VIEW;
    }

}